#include "stm32f10x.h"                  // Device header
#include "Delay.h"
#include "key.h"
#include "OLED.h"
#include "PWM.h"

int main(void)
{
	OLED_Init();
	Key_init();
	PWM_Init();
	
	OLED_ShowString(1, 1, "Speed:");
	
	int16_t speed = 0;
	OLED_ShowSignedNum(1, 7, speed, 2);
	
	uint8_t up = 0;
	
	while(1) {
		uint8_t keyNum = Key_getNum();
		if (keyNum == 1) {
			if (up) {
				speed ++;
				PWM_SetSpeed(speed);
				OLED_ShowSignedNum(1, 7, speed, 2);
				if (speed >= 10) {
					up = 0;
				}
			} else {
				speed --;
				PWM_SetSpeed(speed);
				OLED_ShowSignedNum(1, 7, speed, 2);
				if (speed <= -10) {
					up = 1;
				}
			}
		} 
	}
}
